package srzy.module

import srzy.common.ShellExecute

object ShellComp extends AbsCaseDeal with srzy.common.Logging {

  def deal = {

    val shellCompInfos = getCaseInfo.shellCompInfos
    //    log.debug("dbCompInfos:" + dbCompInfos)
    for (shellCompInfo <- shellCompInfos) {
      try {
        shellCompInfo.shell

        val se = new ShellExecute {
          val shell = shellCompInfo.shell
        }
        se.execute
        shellCompInfo.result = se.out

        logger.debug("PreResult:[" + shellCompInfo.preResult + "]")
        logger.debug("actualResult:[" + shellCompInfo.result + "]")

        if (!(shellCompInfo.preResult == shellCompInfo.result)) {
          shellCompInfo.compResult = false
          fail
        }
        logger.debug("CompResult:[" + shellCompInfo.compResult + "]")
      } catch {
        case ex: Exception => {
          logger.error(ex.getMessage(), ex)
          shellCompInfo.compResult = false
          fail
        }
      }

    }
  }
  def fail = {
    getCaseInfo.shellCompResult = false
    getCaseInfo.caseResult = false
  }
}